package com.baizhi.hospital.service.impl;

import com.baizhi.hospital.annotation.LogAnnotation;
import com.baizhi.hospital.dao.DepartmentDao;
import com.baizhi.hospital.entity.Department;
import com.baizhi.hospital.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired(required = false)
    private DepartmentDao departmentDao;
    @Override
    //@LogAnnotation(value = "查询部门信息",type = "selectDepartmentByPage")
    public Map selectDepartmentByPage(int page, int limit, String departmentName) {
        if(departmentName==null||departmentName==" "){
            departmentName=null;
        }else{
            departmentName="%"+departmentName+"%";
        }
        int start=(page-1)*limit;
        int count=departmentDao.selectCount(departmentName);
        List<Department> departments = departmentDao.selectDepartmentByPage(start, limit, departmentName);
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",departments);
        return map;
    }

    @Override
    //@LogAnnotation(value = "添加部门信息",type = "insert")
    public Map insert(Department department) {
        int count = departmentDao.insert(department);
        Map map=new HashMap();
        if(count>0){
            map.put("isInsert",true);
        }else{
            map.put("isInsert",false);
        }
        return map;
    }

    @Override
    //@LogAnnotation(value = "删除部门信息",type = "delete")
    public Map delete(int departmentId) {
        int count=departmentDao.delete(departmentId);
        Map map=new HashMap();
        if(count>0){
            map.put("isRemove",true);
        }else{
            map.put("isRemove",false);
        }
        return map;
    }

    @Override
    //@LogAnnotation(value = "查询部门信息",type = "selectOne")
    public Department selectOne(int departmentId) {
        return departmentDao.selectOne(departmentId);
    }

    @Override
    //@LogAnnotation(value = "更新部门信息",type = "update")
    public Map update(Department department) {
        int count=departmentDao.update(department);
        Map map=new HashMap();
        if(count>0){
            map.put("isUpdate",true);
        }else{
            map.put("isUpdate",false);
        }
        return map;
    }

    @Override
    //@LogAnnotation(value = "批量删除部门信息",type = "multiDelete")
    public Map multiDelete(int[] departmentIds) {
        int count = departmentDao.multiDelete(departmentIds);
        Map map=new HashMap();

        if(count>0){
            map.put("isMultiDelete",true);
        }else{
            map.put("isMultiDelete",false);
        }
        return map;
    }

}
